#include "tool_captrue.h"

Tool_captrue::Tool_captrue(QObject *parent) : QObject(parent)
{

}

QObject *Tool_captrue::getQmlCamera() const
{
    return m_qmlCamera;
}

void Tool_captrue::setQmlCamera(QObject *qmlCamera)
{
    this->m_qmlCamera = qmlCamera;
    if( m_qmlCamera )
    {
        //将QML对象转换为C++对象
        m_camera = qvariant_cast< QCamera* >( m_qmlCamera->property( "mediaObject" ) );

        //将类QVideoFrameProbe的实例化对象_probe的数据来源设为_camera
//        m_probe.setSource( m_camera );

        m_captrue=new QCameraImageCapture(m_camera);


        connect(m_captrue, &QCameraImageCapture::imageCaptured,
           [this](int id, const QImage &preview){
               //处理获取的图像
               qDebug()<<"QCameraImageCapture::imageCaptured"<<id<<preview;
              QImage img=preview;
              emit getCaptrueImage(img);
              m_captrue->cancelCapture();
           });


    }
}
